<!--
 * @Author: 陈俊升 761723995@qq.com
 * @Date: 2023-07-19 11:22:15
 * @LastEditors: 陈俊升 761723995@qq.com
 * @LastEditTime: 2023-11-29 09:00:57
 * @FilePath: /hr_new_vue3/src/views/Management/Contract/ContractCenter/Files/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 合同-合同中心-合同档案库 -->
<template>
  <ContentCard>
    <template #header>
      <PageHeaderNew title="劳动合同" :breadCrumb="['合同', '合同档案', '劳动合同']" :showBack="false"></PageHeaderNew>
    </template>
    <div style="display: flex; justify-content: space-between">
      <nodeOrgChart @clickTree="clickTree" style="margin-right: 10px"></nodeOrgChart>
      <div>
        <ConditionBox :margin-bottom="20" :margin-top="0">
          <template #left>
            <a-input-search :style="{ width: '220px' }" placeholder="姓名" search-button @search="refUserTable.loadData()" @press-enter="refUserTable.loadData()" v-model="nameSearch" />
          </template>
        </ConditionBox>
        <table-turn style="height: 100%" :tableData="getUserTable" ref="refUserTable">
          <a-table-column :width="80">
            <template #title> 序号 </template>
            <template #cell="{ rowIndex }">
              {{ rowIndex + 1 }}
            </template>
          </a-table-column>
          <a-table-column :width="200" data-index="name" title="姓名" />
          <a-table-column :width="200" data-index="mobile" title="手机号码" />
          <a-table-column :width="200" data-index="companyId" title="公司">
            <template #cell="{ record }">
              {{
                companyList.find((item) => item.id === record.companyId)
                  ?.name || '-'
              }}
            </template>
          </a-table-column>
          <a-table-column :width="200" data-index="positionLevel" title="入职部门">
            <template #cell="{ record }">
              {{
                positionLevelList.find(
                  (item) => item.id === record.positionLevel
                )?.name || '-'
              }}
            </template>
          </a-table-column>
          <a-table-column :width="200" data-index="positionName" title="职位" />
          <a-table-column :width="200" data-index="natureWork" title="工作性质" />
          <a-table-column :width="200" data-index="definition" title="员工状态">
            <template #cell="{ record }">
              {{
                record.progress === 1
                  ? '入职申请'
                  : record.progress === 2
                  ? '待入职'
                  : record.progress === 3
                  ? '预入职'
                  : record.progress === 4
                  ? '入职办理'
                  : record.progress === 5
                  ? '正式入职'
                  : record.progress === 6
                  ? '待离职'
                  : record.progress === 7
                  ? '离职'
                  : record.progress === 8
                  ? '放弃入职'
                  : record.progress === 9
                  ? '实习结束'
                  : record.progress === 10
                  ? '转正'
                  : record.progress === 11
                  ? '试用期'
                  : record.progress === 12
                  ? '人事异动'
                  : ''
              }}
            </template>
          </a-table-column>
          <a-table-column :width="200" data-index="entryTime" title="入职时间" />
          <a-table-column :width="120" data-index="contractStatus" title="签署状态" fixed="right">
            <template #cell="{ record }">
              <div :style="{
                  color: contractStatus.find(
                    ({ value }) => value === record.contractStatus
                  )?.color
                }">
                {{
                  contractStatus.find(
                    ({ value }) => value === record.contractStatus
                  )?.text || '-'
                }}
              </div>
            </template>
          </a-table-column>
          <a-table-column :width="110" title="操作" fixed="right">
            <template #cell="{ record }">
              <a-link @click="toUserContractList(record)"> 查看列表 </a-link>
            </template>
          </a-table-column>
        </table-turn>
      </div>
    </div>
  </ContentCard>
</template>

<script lang="ts" setup>
import { GetWaitSignedContractList } from '@/apis/management/contract/contractManagement/waitSigned';
import { GetContractGroup } from '@/apis/management/contract/baseSetting';
import { GetMyContractPage } from '@/apis/management/contract/contractManagement/haveSigned';
import { contractStatus } from '@/utils/dictionary/contract';
import { GetLegalEntityList } from '@/apis/management/organization/organizationManagement/LegalEntity/index';
import { GetPositionLevelList } from '@/apis/management/organization/baseSetting';
import nodeOrgChart from '../../ContractCenter/Files/Components/NodesOrgChart/index.vue';

let router = useRouter();

let toUserContractList = (record: any) => {
  localStorage.setItem('UserContractData', JSON.stringify({ ...record }));
  router.push({ name: 'UserContractList' });
};

let nameSearch = ref(''); // 搜索框值

// 加载用户列表
let refUserTable = ref();
const getUserTable = async (pageData: any) => {
  try {
    const res = await GetWaitSignedContractList({
      ...pageData,
      codes: '1,2,3,4,5,6,7,8,9,10,11,12,13',
      name: nameSearch.value
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};

//加载基础数据
let companyList = ref<any[]>([]);
let positionLevelList = ref<any[]>([]);
let loadData = async () => {
  let [legalEntity, positionLevel] = await Promise.all([
    GetLegalEntityList({ pageNumber: 0, pageSize: -1 } as any),
    GetPositionLevelList({ page: 1, size: -1 })
  ]);
  companyList.value = legalEntity?.content || [];
  positionLevelList.value = positionLevel?.content || [];
};
loadData();
</script>

<style scoped lang="less">
.contractHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  padding-left: 15px;
  padding-right: 15px;
  &-title {
    font-size: 18px;
    font-weight: 600;
  }
}
</style>
